package cn.edu.gdgm.common.entity;

import lombok.Data;

import java.util.HashMap;

/**
 * @author quan
 * @date 2021-02-27
 */
@Data
public class Result extends HashMap<String, Object> {
    /** 状态码 */
    public static final String CODE = "code";

    /** 返回内容 */
    public static final String MSG = "msg";

    /** 数据对象 */
    public static final String DATA = "data";


    public Result(int code, String msg)
    {
        super.put(CODE, code);
        super.put(MSG, msg);
    }

    public Result(int code, String msg, Object data)
    {
        super.put(CODE, code);
        super.put(MSG, msg);
        super.put(DATA, data);
    }


    public static Result success(String msg) {
        return Result.success(msg, null);
    }

    public static Result success(String msg, Object data) {
        return new Result(200, msg, data);
    }

    public static Result success()
    {
        return Result.success("操作成功");
    }

    public static Result success(Object data)
    {
        return Result.success("操作成功", data);
    }


    public static Result error(int code, String msg) {
        return new Result(code, msg);
    }

}
